﻿using System;

namespace enyo
{
    using enyo.db8;

    [NonScript]
    public abstract class DbServiceMethod
    {
        public static implicit operator DbServiceMethod(string val)
        {
            return null;
        }

        /// <summary>
        /// Execute put, get, del, find (without a watch) and merge operations in one service request. All other database operations are not allowed. Atomicity is NOT guaranteed across batched operations.
        /// </summary>
        //Extend:Not support yet.
        //[EvalAtCompile]
        //public const string Batch = "batch";

        /// <summary>
        /// Deletes objects from the database. Objects can be specified using a query or array of object IDs.
        /// </summary>
        [EvalAtCompile]
        public const string Del = "del";

        /// <summary>
        /// Deletes a JSON kind object from the database. All objects of that kind are also deleted.
        /// </summary>
        [EvalAtCompile]
        public const string DelKind = "delKind";

        /// <summary>
        /// Finds objects matching a query.
        /// </summary>
        [EvalAtCompile]
        public const string Find = "find";

        /// <summary>
        /// Gets objects by ID. Returns array of complete objects. Fastest way to get data from database storage.
        /// </summary>
        [EvalAtCompile]
        public const string Get = "get";

        /// <summary>
        /// Updates properties in existing objects. Similar to SQL UPDATE. Objects can be specified using a query or array of object IDs.
        /// </summary>
        [EvalAtCompile]
        public const string Merge = "merge";

        /// <summary>
        /// Writes JSON data objects to db8 storage.
        /// </summary>
        [EvalAtCompile]
        public const string Put = "put";

        /// <summary>
        /// Puts a JSON kind object into the database. A kind object must be created before objects of that kind are stored.
        /// </summary>
        [EvalAtCompile]
        public const string PutKind = "putKind";

        /// <summary>
        /// Give permission for another app to access your data.
        /// </summary>
        [EvalAtCompile]
        public const string PutPermissions = "putPermissions";

        /// <summary>
        /// Reserves a block of object IDs.
        /// </summary>
        [EvalAtCompile]
        public const string ReserveIds = "reserveIds";

        /// <summary>
        /// Searches for objects matching a query. Supports the "?" operator, which you can use for full-text searching.
        /// </summary>
        [EvalAtCompile]
        public const string Search = "search";

        /// <summary>
        /// Watch for updates to database that would change the results of a query.
        /// </summary>
        [EvalAtCompile]
        public const string Watch = "watch";
    }

    public class DbService : PalmService
    {
        /// <summary>
        /// Db kind for this store.
        /// </summary>
        public string DbKind { get; set; }

        public bool reCallWatches { get; set; }

        public new DbServiceMethod Method { get; set; }

        /// <summary>
        /// Check the db8 namespace for available param kind.
        /// </summary>
        /// <param name="param"></param>
        public void Call(DbParam param)
        {
        }
    }
}
